home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / MSG Demo 1.4.source Folder / Demo ƒ / Shell ƒ / about.c < prev    next >
Text File  |  1994-04-16  |  5KB  |  186 lines

  1. /**********************************************************************\
  2.  
  3. File:        about.c
  4.  
  5. Purpose:    This module handles displaying the about box.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "graphics.h"        /* needs to come first because it defines WindowDataHandle */
  25. #include "about.h"
  26. #include "prefs.h"
  27. #include "util.h"
  28.  
  29. /*-----------------------------------------------------------------------------------*/
  30. /* internal stuff for about.c                                                        */
  31.  
  32. void SetupTheAboutBox(WindowDataHandle theData);
  33. void OpenTheAboutBox(WindowDataHandle theData);
  34. void ShutdownTheAboutBox(WindowDataHandle theData);
  35. void DrawTheAboutBox(Boolean isColor);
  36. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine);
  37. void DrawTheAboutString(Str255 theString, int *theRow);
  38.  
  39. PicHandle        gAboutColorPict;
  40. PicHandle        gAboutBWPict;
  41. Boolean            gUseAlternate;
  42.  
  43. enum
  44. {
  45.     kAboutColorID=134,
  46.     kAboutBWID
  47. };
  48.  
  49. int AboutBoxDispatch(ExtendedWindowDataHandle theData, int theMessage, unsigned long misc)
  50. {
  51.     int                theDepth;
  52.     
  53.     switch (theMessage)    /* see graphics.h for list of messages*/
  54.     {
  55.         case kKeydown:                            /* close about box on keypress */
  56.         case kMousedown:                        /* or mouseclick */
  57.             CloseTheWindow(theData);
  58.             return kSuccess;
  59.             break;
  60.         case kUpdate:
  61.             theDepth=misc&0x7fff;                /* pixel depth */
  62.             DrawTheAboutBox((theDepth>2));        /* we only care if it's color or not */
  63.             return kSuccess;
  64.             break;
  65.         case kOpen:
  66.             OpenTheAboutBox(theData);
  67.             return kSuccess;
  68.             break;
  69.         case kStartup:
  70.             SetupTheAboutBox(theData);
  71.             return kSuccess;
  72.             break;
  73.         case kShutdown:
  74.             ShutdownTheAboutBox(theData);
  75.             return kSuccess;
  76.             break;
  77.     }
  78.     
  79.     return kFailure;        /* for all other messages, defer to default processing */
  80. }
  81.  
  82. void SetupTheAboutBox(WindowDataHandle theData)
  83. {
  84.     unsigned char    *theTitle="\pAbout MSG Demo";
  85.     
  86.     (**theData).windowWidth=380;
  87.     (**theData).windowHeight=216;
  88.     (**theData).windowType=noGrowDocProc;    /* plain vanilla window */
  89.     Mymemcpy((**theData).windowTitle, theTitle, theTitle[0]+1);
  90.     (**theData).hasCloseBox=TRUE;
  91.     gAboutColorPict=gAboutBWPict=0L;
  92.     gUseAlternate=FALSE;
  93. }
  94.  
  95. void OpenTheAboutBox(WindowDataHandle theData)
  96. {
  97.     unsigned int    theKeys[8];
  98.     
  99.     GetKeys(&theKeys);
  100.     if (theKeys[3]&4)    /* option key down? */
  101.     {
  102.         if (!gUseAlternate)
  103.         {
  104.             gUseAlternate=TRUE;
  105.             (**theData).offscreenNeedsUpdate=TRUE;
  106.         }
  107.     }
  108.     else
  109.     {
  110.         if (gUseAlternate)
  111.         {
  112.             gUseAlternate=FALSE;
  113.             (**theData).offscreenNeedsUpdate=TRUE;
  114.         }
  115.     }
  116. }
  117.  
  118. void ShutdownTheAboutBox(WindowDataHandle theData)
  119. {
  120.     if (ReleaseThePict(gAboutColorPict))
  121.         gAboutColorPict=0L;
  122.     if (ReleaseThePict(gAboutBWPict))
  123.         gAboutBWPict=0L;
  124. }
  125.  
  126. void DrawTheAboutBox(Boolean isColor)
  127. {
  128.     int                row;
  129.     Handle            textHandle;
  130.     Str255            theLine;
  131.     unsigned long    pos;
  132.     unsigned long    theSize;
  133.     GrafPtr            curPort;
  134.     
  135.     GetPort(&curPort);
  136.     EraseRect(&(curPort->portRect));
  137.     
  138.     DrawThePicture(isColor ? &gAboutColorPict : &gAboutBWPict, isColor ? kAboutColorID :
  139.         kAboutBWID, 0, 0);
  140.     
  141.     TextFont(geneva);
  142.     TextSize(9);
  143.     TextMode(srcCopy);
  144.     if (isColor)
  145.         ForeColor(blueColor);
  146.     row=16;
  147.     textHandle=GetResource('TEXT', gUseAlternate ? 129 : 128);
  148.     if (textHandle==0L)
  149.         return;
  150.     if (*textHandle==0L)
  151.         LoadResource(textHandle);
  152.     if (*textHandle==0L)
  153.         return;
  154.     pos=0L;
  155.     theSize=SizeResource(textHandle);
  156.     do
  157.     {
  158.         GetTheNextLine(textHandle, theSize, &pos, theLine);
  159.         DrawTheAboutString(theLine, &row);
  160.     }
  161.     while (pos<theSize);
  162.     ReleaseResource(textHandle);
  163.     if (isColor)
  164.         ForeColor(redColor);
  165.     DrawTheAboutString(gMyName, &row);
  166.     DrawTheAboutString(gMyOrg, &row);
  167.     if (isColor)
  168.         ForeColor(blackColor);
  169. }
  170.  
  171. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine)
  172. {
  173.     unsigned char    theChar;
  174.     
  175.     theLine[0]=0x00;
  176.     while ((*pos<theSize) && ((theChar=*((unsigned char*)(((long)(*textHandle))+((*pos)++))))!=0x0d))
  177.         theLine[++theLine[0]]=theChar;
  178. }
  179.  
  180. void DrawTheAboutString(Str255 theString, int *theRow)
  181. {
  182.     MoveTo(293-StringWidth(theString)/2, *theRow);
  183.     DrawString(theString);
  184.     *theRow+=12;
  185. }
  186.